home *** CD-ROM | disk | FTP | other *** search
- /*
- CDElapsed - An XFCN to report elapsed time on disc
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDElapsed.c
- link -sn Main=CDElapsed -sn STDIO=CDElapsed ∂
- -sn INTENV=CDElapsed -rt XFCN=42 ∂
- -m CDElapsed CDElapsed.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- OSErr ReadQ(short, long *, long *, long *, long *);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDElapsed
- *
- * Purpose: return the elapsed time on this disc.
- *
- * Returns: either 0, or an error
- * if it's a negative number, it's an error
- *
- * Side Effects:
- *
- * Description: We need no parameters:
- * Get the ioRefNum that we got from previously calling
- * CDOpen(), using the famous global.
- * call the driver with a READQ call to find out
- * how absolute minute, second, block elapsed.
- *
- ************************************************************************/
- pascal void
- CDElapsed(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- long ElapsedDisc[4]; /* minute, second, block */
-
- /* Must be no parameters */
- if ((paramPtr->paramCount) != 0)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
-
- result = ReadQ(ioRefNum, &ElapsedDisc[0], &ElapsedDisc[1], &ElapsedDisc[2], &ElapsedDisc[3]);
-
- if (result == noErr)
- {
- /* convert each value to a string, concatenate, & return. */
- FormatString(&returnString, ElapsedDisc, 4);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- else
- {
- /* We got an error. Convert result to string & return it as error */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- }
-
- /************************************************************************
- *
- * Function: ReadQ
- *
- * Purpose: return current track & elapsed time for current track
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: none
- *
- * Description: Simply call the driver with a READQ call. The absolute
- * minute, second, block come back in BCD. Convert them
- * to decimal and return them.
- *
- ************************************************************************/
- OSErr
- ReadQ(refNum, trackNo, minute, second, block)
- short refNum;
- long *trackNo;
- long *minute;
- long *second;
- long *block;
- {
- CDParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = READQ;
-
- result = PBControl(&myPB, false);
-
- if (result == noErr)
- {
- *trackNo = (long) BCD2DECIMAL(myPB.csParam[1]);
- *minute = (long) BCD2DECIMAL(myPB.csParam[6]);
- *second = (long) BCD2DECIMAL(myPB.csParam[7]);
- *block = (long) BCD2DECIMAL(myPB.csParam[8]);
- }
- return result;
- }
-
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-